package bairui.international.console.web.controller.personnel.department;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lianjing.sh.spring.web.controller.base.action.Action;
import com.lianjing.sh.spring.web.controller.enhance.output.FomatOutput;

import bairui.international.model.domain.jpa.QTB_Department;
import bairui.international.service.Service_Department;


/**
 * @generated
 *
 * C_Personnel_Department_Tree
 *
 */
@Controller
public class C_Personnel_Department_Tree
 extends SC_Personnel_Department_Tree 
{
	
	@Autowired @Lazy private Service_Department service_Department;
	
	private static final QTB_Department QRoot = QTB_Department.tB_Department;
	
	/**
	 * 树
	 */
	@Action(Tree.class)
	@GetMapping(value=Tree.RequestMappingValue, consumes=MediaType.APPLICATION_JSON_VALUE)
	public @FomatOutput @ResponseBody Object tree(
		HttpServletRequest request, 
		@PathVariable(name=Tree.PathVariableName.ParentId) Long parentId
	) throws Exception {
		if(null != parentId){
			return Tree.Output.output(
					service_Department.findSubDepartment(parentId, QRoot.orderValue.desc())
				);
		}else{
			return Tree.Output.output(
					service_Department.findRootDepartment(QRoot.orderValue.desc())
				);
		}
	}
	
}


